package com.jjc.android.activity

import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.jjc.android.Constants
import com.jjc.android.R
import com.jjc.android.adapter.OperationVideoAdapter
import com.jjc.android.base.BaseActivity
import com.jjc.android.entity.*
import com.jjc.android.net.SimpleHttpCallback
import com.jjc.android.util.MultiLanguageUtil
import com.jjc.android.util.SimpleOnRefreshLoadMoreListener
import com.jjc.android.util.paramEx
import com.lzy.okgo.OkGo
import com.scwang.smart.refresh.layout.SmartRefreshLayout

class OperationVideoActivity : BaseActivity(){

    companion object{
        fun start(context: Context, primaryClassifyId:String, secondaryClassifyId:String){
            val intent = Intent(context,OperationVideoActivity::class.java)
            intent.putExtra("primaryClassifyId",primaryClassifyId)
            intent.putExtra("secondaryClassifyId",secondaryClassifyId)
            context.startActivity(intent)
        }
    }

    override val layoutId: Int = R.layout.activity_operation_video
    private val smartRefreshLayout: SmartRefreshLayout by lazy { findViewById<SmartRefreshLayout>(R.id.smartRefreshLayout) }
    private val recyclerView: RecyclerView by lazy { findViewById<RecyclerView>(R.id.recyclerView) }
    private lateinit var mAdapter:OperationVideoAdapter
    private var primaryClassifyId:String = ""
    private var secondaryClassifyId:String = ""
    private val refreshLayoutDelegate by lazy {
        object : SimpleOnRefreshLoadMoreListener(){
            override fun invokeActivity(block: BaseActivity.() -> Unit) {
                this@OperationVideoActivity.apply(block)
            }

            override fun loadPage(
                page: Int,
                actionSuccess: (Int, List<Any>?) -> Unit,
                actionError: (Int, String?) -> Unit
            ) {
                OkGo.post<LzyResponse<PageInfo<OperationVideoDto>>>(Constants.getFormList)
                    .paramEx(mutableMapOf("page" to page.toString(),"pagesize" to Constants.PAGE_SIZE.toString(),"needpage" to 1,"formheaduuid" to "82701bfc08714ac8a18e4a7507deae11","filters" to listOf<KeyValuePair>(
                        KeyValuePair("vnmzmquyysauypev",secondaryClassifyId),
                        KeyValuePair("dzehvyavob24gjg2",MultiLanguageUtil.getInstance().getValue("f7cace96-2cb5-4873-b316-389c2522969e","98bde949-f24c-46d4-9913-dac0fa903121"))
                    )),true)
                    .tag(this)
                    .execute(object : SimpleHttpCallback<LzyResponse<PageInfo<OperationVideoDto>>>(false){
                        override fun onCallSuccess(response: LzyResponse<PageInfo<OperationVideoDto>>) {
                            actionSuccess.invoke(page,response.data?.data)
                        }

                        override fun onCallError(error: String?) {
                            super.onCallError(error)
                            actionError.invoke(page,error)
                        }
                    })
            }
        }
    }
    override fun initView(savedInstanceState: Bundle?) {
        setActivityTitle(getString(R.string.operate_video_txt))
        recyclerView.layoutManager = LinearLayoutManager(this)
        mAdapter = OperationVideoAdapter()
        recyclerView.adapter = mAdapter
        refreshLayoutDelegate.init(smartRefreshLayout,recyclerView,false)
    }

    override fun setupArguments(args: Bundle?) {
        primaryClassifyId = args?.getString("primaryClassifyId")?:""
        secondaryClassifyId = args?.getString("secondaryClassifyId")?:""
    }
}